/**
 * 供应商应收
 */

import { fileGet, filePost, post, postFormData } from '@/request/http'
import store from '@/store'

const url = '/FTKJWLHYPT/bill/'

/**
 * 客户列表
 * @param {*} data
 */
export const queryCollCustomer = () =>
  post(url + 'queryCollCustomer', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          dptFltId: store.state.user.FLT_UUID_DX_H,
        },
      },
    },
  })

/**
 * 合同列表
 * @param {} data
 */
export const queryFeeContract = data =>
  post(url + 'queryFeeContract', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          startTime: data.startTime,
          endTime: data.endTime,
          cbId: data.cbId,
          cmtPartyB: data.cmtPartyB,
          cmtPartyA: data.cmtPartyA,
          cbBillType: data.cbBillType,
          checked: data.checked,
          cbType: data.cbType,
        },
      },
      PageIndex: {
        FTKJWLHYPT: data.index,
      },
      PageSize: {
        FTKJWLHYPT: data.size,
      },
    },
  })

/**
 * 运单列表
 * @param {*} data
 */
export const queryFeeWayByCon = data =>
  post(url + 'queryFeeWayByCon', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmtNo: data.no,
          checked: data.checked,
        },
      },
    },
  })

/**
 * 结算单生成
 * @param {*} data
 */
export const addChargeBill = data =>
  post(url + 'addBill', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbNo: data.cbNo,
          cbBillNo: data.cbBillNo,
          cbBillName: data.cbBillName,
          cbBillStatus: data.cbBillStatus,
          cbPrice: data.cbPrice,
          cbSettlemode: data.cbSettlemode,
          cbType: data.cbType,
          cbBillTotal: data.cbBillTotal,
          cbRemark: data.cbRemark,
          cbFltId: data.cbFltId,
          cbDptId: store.state.user.DPTID_DX_H,
          cbCreateer: store.state.user.USR_CODE_DX_H,
          cbIsDel: data.cbIsDel,
          cbBillCmtId: data.cbBillCmtId,
          cbBillType: data.cbBillType,
          cbJpayer: data.cbJpayer,
          cbWeight: data.cbWeight,
          itemDTOList: data.itemDTOList,
          cbBillAttId: data.cbBillAttId,
          cbiGenSource: data.genSource,
          cbFinancialService: data.cbFinancialService,
        },
      },
    },
  })

/**
 * 查询结算单列表
 * @param {*} data
 */
export const queryChargeBill = data =>
  post(url + 'queryBill', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbJpayer: data.cbJpayer,
          cbJpayerName: data.cbJpayerName,
          cbFltId: store.state.user.FLT_UUID_DX_H,
          cbDptId: store.state.user.DPTID_DX_H,
          cbBillType: data.cbBillType,
          cbType: data.cbType,
          source: data.source,
          payB: data.payB,
          isSearchInfo: data.isSearchInfo,
          payA: data.payA,
          payAName: data.payAName,
          startTime: data.startTime,
          endTime: data.endTime,
          cbBillNo: data.cbBillNo,
          cbNo: data.contractNo,
        },
      },
      PageIndex: {
        FTKJWLHYPT: data.index,
      },
      PageSize: {
        FTKJWLHYPT: data.size,
      },
    },
  })

export const delChargeBill = data =>
  post(url + 'delBill', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbId: data.cbId,
          cbEditer: store.state.user.USR_CODE_DX_H,
        },
      },
    },
  })

/**
 * 结算单细项
 * @param {*} data
 */
export const queryBillItem = data =>
  post(url + 'queryBillItem', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbiCbId: data.billId,
        },
      },
    },
  })

/**
 * 结算单细项批量
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export const queryBillItemList = data =>
  post(url + 'queryBillItemList', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          list: data,
        },
      },
    },
  })

/**
 * 修改结算单
 * @param {*} data
 */
export const updateBill = data =>
  post(url + 'updateBill', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbId: data.cbId,
          cbBillNo: data.cbBillNo,
          cbBillName: data.cbBillName,
          cbBillStatus: data.cbBillStatus,
          cbPrice: data.cbPrice,
          cbSettlemode: data.cbSettlemode,
          cbType: data.cbType,
          cbBillTotal: data.cbBillTotal,
          cbRemark: data.cbRemark,
          cbFltId: store.state.user.FLT_UUID_DX_H,
          cbDptId: store.state.user.DPTID_DX_H,
          cbCreateer: store.state.user.USR_CODE_DX_H,
          cbIsDel: data.cbIsDel,
          cbBillCmtId: data.cbBillCmtId,
          cbBillType: data.cbBillType,
          cbJpayer: data.cbJpayer,
          cbWeight: data.cbWeight,
          itemDTOList: data.itemDTOList,
        },
      },
    },
  })

/**
 * 状态确认
 * @param {*} data
 */
export const confirmationResults = data =>
  post(url + 'confirmationResults', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbId: data.cbId,
          cbEditer: store.state.user.USR_CODE_DX_H,
          cbBillStatus: data.status,
        },
      },
    },
  })

/**
 * 批量状态确认
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export const confirmationResultsList = data =>
  post(`${url}confirmationResultsList/${data.status}`, {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          data: data.ids,
        },
      },
    },
  })

/**
 * 供应商对账页面查询
 */
export const queryPlatformWithSupplierBill = data =>
  post(url + 'queryPlatformWithSupplierBill', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbFltId: data.cbJpayer,
          cbJpayer: store.state.user.FLT_UUID_DX_H,
          cbType: data.cbType,
          cbBillNo: data.cbBillNo,
          startTime: data.startTime,
          endTime: data.endTime,
          cbNo: data.contractNo,
          cbDocumentCode: data.cbDocumentCode,
        },
      },
      PageIndex: {
        FTKJWLHYPT: data.index,
      },
      PageSize: {
        FTKJWLHYPT: data.size,
      },
    },
  })

/**
 * 平台与供应商对账下拉框
 * @param {*} data
 */
export const queryReconciliationSupplierList = () =>
  post(url + 'queryReconciliationSupplierList', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {},
      },
    },
  })

/**
 * 导出结算单 Excle
 * @param {*} data
 */
export const exportStatement = data =>
  filePost(`${url}exportStatement/${data.type}/${data.yht}/${data.section}`, {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          data: data.ids,
        },
      },
      PageIndex: {
        FTKJWLHYPT: data.index,
      },
      PageSize: {
        FTKJWLHYPT: data.size,
      },
    },
  })

/**
 * 单据下载
 * @param data
 * @returns {*}
 */
export const downBillsFile = data => fileGet(url + 'downBillsFile/' + data.id)

/**
 * 平台与客户对账
 * @param {*} data
 */
export const queryPlatformCustomerBill = data =>
  post(url + 'queryPlatformCustomerBill', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbFltId: data.cbFltId,
          cbJpayer: data.cbJpayer,
          cbType: data.cbType,
          source: data.source,
          cbBillNo: data.cbBillNo,
          startTime: data.startTime,
          endTime: data.endTime,
          preDptId: data.preDptId,
          cbNo: data.contractNo,
        },
      },
      PageIndex: {
        FTKJWLHYPT: data.index,
      },
      PageSize: {
        FTKJWLHYPT: data.size,
      },
    },
  })

/**
 * 平台与客户对账下拉框查询
 * @param {*} data
 */
export const queryPlatformCustomerDropDownBill = data =>
  post(url + 'queryPlatformCustomerDropDownBill', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          source: data.source,
        },
      },
    },
  })

/**
 * 获取结算单编号
 */
export const genBillNo = data =>
  post(url + 'genBillNo', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbBillCmtId: data.cbBillCmtId,
        },
      },
    },
  })

/**
 * 未结算客户下拉
 * @param {*} data
 */
export const queryCollDiaCustomer = () =>
  post(url + 'queryCollDiaCustomer', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          dptFltId: store.state.user.FLT_UUID_DX_H,
        },
      },
    },
  })

/**
 * 单据上传
 * @param {} data
 */
export const upBillDocument = data => postFormData(url + 'upBillDocument/' + store.state.user.USR_CODE_DX_H, data)
/**
 * 附件上传
 * @param {} data
 */
export const upContractDocument = data => postFormData('/FTKJWLHYPT/' + 'contractupload/' + data.id + '/' + store.state.user.USR_CODE_DX_H, data.file)

/**
 * 发起收款修改单据信息
 * @param {*} data
 */
export const updateBillSelective = data =>
  post(url + 'updateBillSelective', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbEditer: store.state.user.USR_CODE_DX_H,
          cbDocumentNo: data.cbDocumentNo,
          cbId: data.cbId,
          cbDocumentCode: data.documentCode,
          cbDocumentIdentifier: data.documentIdentifier,
          cbDocumentDate: data.documentDate,
          cbDocumentNoTaxAmount: data.documentNoTaxAmount,
          cbDocumentTaxAmount: data.documentTaxAmount,
          cbDocumentTotalAmount: data.documentTotalAmount,
          cbIsInfo: data.cbIsInfo,
          documents: data.documentList,
        },
      },
    },
  })

/**
 * 服务费查询
 * @param {*} data
 */
export const queryServiceBills = data =>
  post(url + 'queryServiceBills', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          startTime: data.startTime,
          endTime: data.endTime,
          payB: data.payB,
          payA: data.payA,
          cbId: data.billid,
          source: data.source,
          cbBillNo: data.cbBillNo,
        },
      },
      PageIndex: {
        FTKJWLHYPT: data.index,
      },
      PageSize: {
        FTKJWLHYPT: data.size,
      },
    },
  })

/**
 * 平台确认生成新结算单
 */
export const platformConfirm = data =>
  post(url + 'platformConfirm', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cbId: data.cbId,
          cbDocumentCode: data.documentCode,
          cbDocumentIdentifier: data.documentIdentifier,
          cbDocumentDate: data.documentDate,
          cbDocumentNoTaxAmount: data.documentNoTaxAmount,
          cbDocumentTaxAmount: data.documentTaxAmount,
          cbDocumentTotalAmount: data.documentTotalAmount,
          cbDocumentNo: data.cbDocumentNo,
        },
      },
    },
  })

/**
 * 工作台查询全部金额
 */
// export const selectMoneyAll = (data) => post(
//   url + 'selectMoneyAll',
//   {
//     Data: {
//       Parameters: {
//         FTKJWLHYPT: {
//           cbJpayer: store.state.user.DPTID_DX_H,
//           cbFltId: store.state.user.FLT_UUID_DX_H,
//         }
//       }
//     }
//   }
// )

/**
 * 服务费合同查询
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export const queryInfoContract = data =>
  post(url + 'queryInfoContract', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          startTime: data.startTime,
          endTime: data.endTime,
          cmtPartyB: data.cmtPartyB,
          cbId: data.billId,
          bidId: data.bidId,
        },
      },
      PageIndex: {
        FTKJWLHYPT: data.index,
      },
      PageSize: {
        FTKJWLHYPT: data.size,
      },
    },
  })

export const updateBillsSelective = data =>
  post(url + 'updateBillsSelective', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          data,
        },
      },
    },
  })
